let username;
let password;
let phone;
let age;
let sex;
let ai;
let sheng;
let shi;
let qu;
let jieshao;

function tijiao() {

    username = document.getElementById("username").value;
    password = document.getElementById("password").value;
    phone = document.getElementById("phone").value;
    age = document.getElementById("age").value;
    let sexs = document.getElementsByName("sex");

    for (let i = 0; i < sexs.length; i++) {
        // console.log(sexs[i].checked+sexs[i].value);
        if (sexs[i].checked) {
            sex = sexs[i].value;
        }
    }
    let aihao = document.getElementsByName("aihao");
    ai = [];
    for (let i = 0; i < aihao.length; i++) {
        // console.log(aihao[i].checked+aihao[i].value)
        if (aihao[i].checked) {
            ai.push(aihao[i].value);
        }
    }



    // console.log(ai);
    sheng = document.getElementById("sheng").value;
    shi = document.getElementById("shi").value;
    // let ss = document.getElementById("sheng");

    qu = document.getElementById("qu").value;
    jieshao = document.getElementById("jieshao").value;

    document.getElementById("xianshi").innerHTML =
        "姓名：" + username + "<br>"
        + "密码：" + password + "<br>"
        + "手机：" + phone + "<br>"
        + "年龄：" + age + "<br>"
        + "性别：" + sex + "<br>"
        + "爱好：" + ai + "<br>"
        + "住址：" + sheng + shi + qu + "<br>"
        + "自我评价：" + jieshao + "<br>";


}

function xiugai() {
    document.getElementById("username").value = username;
    document.getElementById("password").value = password;
    document.getElementById("phone").value = phone;
    document.getElementById("age").value = age;
    // document.getElementById("sex").value = sex;
    let sexs = document.getElementsByName("sex");
    for (let i = 0; i < sexs.length; i++) {
        if (sex == sexs[i].value) {
            sexs[i].checked = true;
        }
    }
    // document.getElementById("ai").value = ai;
    let aihao = document.getElementsByName("aihao");
    let a = 0;
    for (let i = 0; i < aihao.length; i++) {
        //嵌套循环
        for (let j = 0; j < ai.length; j++) {
            if (ai[j] == aihao[i].value) {
                aihao[i].checked = true;
            }
            a++;
        }
    }
    console.log(a);
    document.getElementById("sheng").value = sheng;
    document.getElementById("shi").value = shi;
    document.getElementById("qu").value = qu;


    document.getElementById("jieshao").value = jieshao;
}